import jQuery from 'jquery';
import {stringUtils} from "../utils/stringUtils";


(function (self) {

    const playerUrl = "http://esp-developer-service.edu.web.sdp.101.com/v0.1/players/{code}/latest_version";
    const onlineBase = "http://cs.101.com/v0.1/static/esp_developer";

    if(self.midwayBoot === undefined) {
        Object.defineProperty(self, 'midwayBoot', {
            value: function (options) {

            }
        });
        
        self.midwayBoot = function () {
            
        };
    }

    function loadOnlinePlayerInfo(code) {
        const requestUrl = playerUrl.replace('{code}', code);
        let midwayUrl, midwareUrl;
        jQuery.ajax({
            url: requestUrl,
            dataType: 'json',
            method: 'GET',
            cache: false,
            async: false
        }).done(function (data) {
            if(data.midware_version) {
                midwayUrl = stringUtils.urlJoin(onlineBase, "modules/InteractionMidware", data.midware_version, "midway/midway.umd.js");
                midwareUrl = stringUtils.urlJoin(onlineBase, "modules/InteractionMidware", data.midware_version, "midway/facade.umd.js");

                //let def1 = ScriptRender.addJavascript(midwayUrl);
                //let def2 = ScriptRender.addJavascript(midwareUrl);
            }
        });
    }

})(typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this);